<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RepFacturaDetallada
 *
 * @author Bryan Cruz
 */
class RepStudInactCiclo extends ReportBase {
    
    public $where = NULL;
    public $stud = "";

    function __construct() {
        $this->callbackSql = "cbSqlGenerador"; //funcion que genera sql
        $this->callbackRow = "funcRows"; //funcion para cada fila generada
        $this->paramPage = "rpt_studInactCiclo_param.php";
        $this->resultPage = "rpt_studInactCiclo_resultado.php";
        $this->rootPath = RPT_PATH + "include";
        $this->label = "Alumnos inactivos por ciclo";
        $this->subtitle = $this->label;
    }

    public function funcRows() {
        $newResult = array();
        foreach ($this->lastResult as $r) {
            $sql = "select * from cllg_factura";
            $rs = $this->query($sql);
            
        }
        $this->lastResult = $newResult;
    }

    /**
     * Genera el sql para el reporte
     */
    public function getFields() {
        #$this->fields = isset($_POST['selFields']) ? NULL : $_POST['selFields'];
         if (isset($_POST['selFields'])){
             return $_POST['selFields'];
         }
    }
    
    public function cbSqlGenerador() {
        #EaPdfPrinter::$ORIENTACION = "landscape";
        #$user = AppSecurity::$UserData;
        #$user = $user["data"];
           
        $sql = "SELECT * FROM cllg_student ";
        $w = NULL;
        
        if(getParam("cycle") == 0){
                throw new Exception("<h5 style='color:blue;'>Seleccione ciclo!!<h5>");
        }else{
            $w =sprintf("ID IN ( 
                SELECT DISTINCT FK_STUDENT 
                FROM cllg_student_assign b
                WHERE b.FK_CYCLE=%s 
                AND b.STATUS=0 
                AND b.FK_CAREER=%s 
                AND b.FK_STUDENT NOT IN (
                    SELECT FK_STUDENT 
                    FROM cllg_student_assign
                    WHERE FK_CYCLE=%s 
                    AND FK_CAREER=%s 
                    AND STATUS=1))
                ", getParam("cycle"), getParam("career"), getParam("cycle"), getParam("career"));
        }
        
        $this->lastQuery = isEmpty($w) ? $sql : ("$sql WHERE $w");
    }
 
    
    
    public function generateSQL() {
        
        $this->cbSqlGenerador();
        $sqlRs = $this->db->queryToArray($this->lastQuery);
        $this->lastResult = $sqlRs;
    }
    
    public function setCol($startRow,$tab){
        $fields = array();
        $result = "";
        $fields = $this->db->query_select("cllg_tablefield","TABLE_NAME='cllg_student' AND STATUS !=0 AND FK_TAB=$tab LIMIT $startRow,5");
        foreach($fields as $f){
            $result .= "<td width='2%'><input type='checkbox' name='selFields[]' id='". $f['NAME'] ."' value='". $f['NAME'] ."' />";
            $result .= "<td width='18%' style='padding-top:0.3%;padding-bottom:0'><label for='". $f['NAME'] ."'>". $f['CAPTION']."</label>";        
        }
        return $result;
    }
    
    public function getBaseFields(){
        #$this->fields = isset($_POST['selFields']) ? NULL : $_POST['selFields'];
         if (isset($_POST['baseFields'])){
             return $_POST['baseFields'];
         }
    
    }
}
?>
